package finaldic;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baidu.translate.demo.TransApi;

public class baidudic extends Dict {
	private static final String APP_ID = "20210408000767617";
    private static final String SECURITY_KEY = "UhNKsWDKoQLD9m7kAYdI";
	public String translate(String word) {
    	TransApi api = new TransApi(APP_ID, SECURITY_KEY);
    	String data =api.getTransResult(word, "auto", "zh");
    	JSONObject object =JSONObject.parseObject(data);
    	JSONArray array =object.getJSONArray("trans_result");
    	
    	JSONObject elem=JSONObject.parseObject(array.get(0).toString());
    	
    	String dst =elem.getString("dst");
    	String value=null;
    	try {
    		value= URLDecoder.decode(dst,"utf-8");
    	}catch(UnsupportedEncodingException e) {
    		e.printStackTrace();
    	}
    	return value;
	}
}
